import { BasicColumn, BasicTable, FormSchema, useTable } from "@/components/Table";
import { message } from "antd";
import { DrugInfoApi } from "@/api/erp/drug/drugInfo";
import { useTranslation } from "react-i18next";
import Toolbar from "@/components/ViewComponents/Toolbar";
import CreateAndUpdata from "./components/createAndUpdata";
import { useDrawer } from "@/components/Drawer";
import { exportToExcel } from "@/utils/util";
import { IconEnum } from "@/enums/appEnum";
import TableAction from "@/components/Table/components/TableAction";
const index = () => {
	const { t } = useTranslation();
	const en_vi = "drugStorage.drugManagement.drugInfo";
	const schemas: FormSchema[] = [
		{
			label: t(`${en_vi}.code`),
			field: "code",
			component: "Input"
		},
		{
			label: t(`${en_vi}.name`),
			field: "name",
			component: "Input"
		}
	];
	const columns: BasicColumn[] = [
		{
			title: t(`${en_vi}.code`),
			dataIndex: "code"
		},
		{
			title: t(`${en_vi}.name`),
			dataIndex: "name"
		},
		{
			title: t(`${en_vi}.dosageForm`),
			dataIndex: "dosageForm"
		},
		{
			title: t(`${en_vi}.content`),
			dataIndex: "content"
		},
		{
			title: t(`${en_vi}.groupCode`),
			dataIndex: "groupCode"
		},
		{
			title: t(`${en_vi}.typeCode`),
			dataIndex: "typeCode"
		},
		{
			title: t(`${en_vi}.productCode`),
			dataIndex: "productCode"
		},
		{
			title: t(`${en_vi}.countryCode`),
			dataIndex: "countryCode"
		},
		{
			title: t(`${en_vi}.departmentGroup`),
			dataIndex: "departmentGroup"
		},
		{
			title: t(`${en_vi}.insuranceType`),
			dataIndex: "insuranceType"
		},
		{
			title: t(`${en_vi}.essential`),
			dataIndex: "essential"
		},
		{
			title: t(`${en_vi}.accountNumber`),
			dataIndex: "accountNumber"
		},
		{
			title: t(`${en_vi}.ingredientName`),
			dataIndex: "ingredientName"
		},
		{
			title: t(`${en_vi}.ingredientCode`),
			dataIndex: "ingredientCode"
		},
		{
			title: t(`${en_vi}.groupField`),
			dataIndex: "groupField"
		},
		{
			title: t(`${en_vi}.registrationNumber`),
			dataIndex: "registrationNumber"
		},
		{
			title: t(`${en_vi}.unitPrice`),
			dataIndex: "unitPrice"
		},
		{
			title: t(`${en_vi}.minQuantity`),
			dataIndex: "minQuantity"
		},
		{
			title: t(`${en_vi}.salePrice`),
			dataIndex: "salePrice"
		},
		{
			title: t(`${en_vi}.repaymentDays`),
			dataIndex: "repaymentDays"
		},
		{
			title: t(`${en_vi}.dutyDrug`),
			dataIndex: "dutyDrug"
		},
		{
			title: t(`${en_vi}.postIssuance`),
			dataIndex: "postIssuance"
		},
		{
			title: t(`${en_vi}.ratio`),
			dataIndex: "ratio"
		},
		{
			title: t(`${en_vi}.serialNumber`),
			dataIndex: "serialNumber"
		},
		{
			title: t(`${en_vi}.imagePath`),
			dataIndex: "imagePath"
		},
		{
			title: t(`${en_vi}.typeField`),
			dataIndex: "typeField"
		},
		{
			title: t(`${en_vi}.power`),
			dataIndex: "power"
		},
		{
			title: t(`${en_vi}.printGroup`),
			dataIndex: "printGroup"
		},
		{
			title: t(`${en_vi}.occupationalRelated`),
			dataIndex: "occupationalRelated"
		},
		{
			title: t(`${en_vi}.unitCode`),
			dataIndex: "unitCode"
		},
		{
			title: t(`${en_vi}.unit`),
			dataIndex: "unit"
		},
		{
			title: t(`${en_vi}.patientType`),
			dataIndex: "patientType"
		},
		{
			title: t(`${en_vi}.rounding`),
			dataIndex: "rounding"
		},
		{
			title: t(`${en_vi}.days`),
			dataIndex: "days"
		},
		{
			title: t(`${en_vi}.hidden`),
			dataIndex: "hidden"
		},
		{
			title: t(`${en_vi}.wholeIssue`),
			dataIndex: "wholeIssue"
		},
		{
			title: t(`${en_vi}.packagingQuantity`),
			dataIndex: "packagingQuantity"
		},
		{
			title: t(`${en_vi}.targetCode`),
			dataIndex: "targetCode"
		},
		{
			title: t(`${en_vi}.salePrice2`),
			dataIndex: "salePrice2"
		},
		{
			title: t(`${en_vi}.productionDosageForm`),
			dataIndex: "productionDosageForm"
		},
		{
			title: t(`${en_vi}.usageDosageForm`),
			dataIndex: "usageDosageForm"
		},
		{
			title: t(`${en_vi}.atcCode`),
			dataIndex: "atcCode"
		},
		{
			title: t(`${en_vi}.genericName`),
			dataIndex: "genericName"
		},
		{
			title: t(`${en_vi}.atcClassificationCode`),
			dataIndex: "atcClassificationCode"
		},
		{
			title: t(`${en_vi}.insurancePrice`),
			dataIndex: "insurancePrice"
		},
		{
			title: t(`${en_vi}.technologyType`),
			dataIndex: "technologyType"
		},
		{
			title: t(`${en_vi}.priceDifferenceFlag`),
			dataIndex: "priceDifferenceFlag"
		},
		{
			title: t(`${en_vi}.abcClassification`),
			dataIndex: "abcClassification"
		},
		{
			title: t(`${en_vi}.drugType`),
			dataIndex: "drugType"
		},
		{
			title: t(`${en_vi}.classificationType`),
			dataIndex: "classificationType"
		},
		{
			title: t(`${en_vi}.components`),
			dataIndex: "components"
		},
		{
			title: t(`${en_vi}.indications`),
			dataIndex: "indications"
		},
		{
			title: t(`${en_vi}.contraindications`),
			dataIndex: "contraindications"
		},
		{
			title: t(`${en_vi}.precautions`),
			dataIndex: "precautions"
		},
		{
			title: t(`${en_vi}.pregnancyUsage`),
			dataIndex: "pregnancyUsage"
		},
		{
			title: t(`${en_vi}.interactions`),
			dataIndex: "interactions"
		},
		{
			title: t(`${en_vi}.adverseReactions`),
			dataIndex: "adverseReactions"
		},
		{
			title: t(`${en_vi}.dosage`),
			dataIndex: "dosage"
		},
		{
			title: t(`${en_vi}.administrationRoute`),
			dataIndex: "administrationRoute"
		},
		{
			title: t(`${en_vi}.methodOfUse`),
			dataIndex: "methodOfUse"
		},
		{
			title: t(`${en_vi}.warehouseCode`),
			dataIndex: "warehouseCode"
		},
		{
			title: t(`${en_vi}.bidPrice`),
			dataIndex: "bidPrice"
		},
		{
			title: t(`${en_vi}.abbreviation`),
			dataIndex: "abbreviation"
		},
		{
			title: t(`${en_vi}.dialysisFlag`),
			dataIndex: "dialysisFlag"
		},
		{
			title: t(`${en_vi}.eachDose`),
			dataIndex: "eachDose"
		},
		{
			title: t(`${en_vi}.course`),
			dataIndex: "course"
		},
		{
			title: t(`${en_vi}.hospitalPreparation`),
			dataIndex: "hospitalPreparation"
		},
		{
			title: t(`${en_vi}.phone`),
			dataIndex: "phone"
		},
		{
			title: t(`${en_vi}.hospitalCode`),
			dataIndex: "hospitalCode"
		},
		{
			title: t(`${en_vi}.useUnit`),
			dataIndex: "useUnit"
		},
		{
			title: t(`${en_vi}.prescriptionOtcFlag`),
			dataIndex: "prescriptionOtcFlag"
		},
		{
			title: t(`${en_vi}.pendingApproval`),
			dataIndex: "pendingApproval"
		},
		{
			title: t(`${en_vi}.policyNumber`),
			dataIndex: "policyNumber"
		},
		{
			title: t(`${en_vi}.shortName`),
			dataIndex: "shortName"
		},
		{
			title: t(`${en_vi}.filterCondition`),
			dataIndex: "filterCondition"
		},
		{
			title: t(`${en_vi}.volume`),
			dataIndex: "volume"
		},
		{
			title: t(`${en_vi}.rhdClassification`),
			dataIndex: "rhdClassification"
		},
		{
			title: t(`${en_vi}.surcharge`),
			dataIndex: "surcharge"
		},
		{
			title: t(`${en_vi}.manufacturerCode`),
			dataIndex: "manufacturerCode"
		},
		{
			title: t(`${en_vi}.bidCode`),
			dataIndex: "bidCode"
		},
		{
			title: t(`${en_vi}.lossRate`),
			dataIndex: "lossRate"
		},
		{
			title: t(`${en_vi}.reserveLock`),
			dataIndex: "reserveLock"
		},
		{
			title: t(`${en_vi}.paymentObject`),
			dataIndex: "paymentObject"
		},
		{
			title: t(`${en_vi}.gmpCertification`),
			dataIndex: "gmpCertification"
		},
		{
			title: t(`${en_vi}.stockQuantity`),
			dataIndex: "stockQuantity"
		},
		{
			title: t(`${en_vi}.catalogFlag`),
			dataIndex: "catalogFlag"
		},
		{
			title: t(`${en_vi}.userId`),
			dataIndex: "userId"
		},
		{
			title: t(`${en_vi}.vat`),
			dataIndex: "vat"
		},
		{
			title: t(`${en_vi}.orderNumber`),
			dataIndex: "orderNumber"
		},
		{
			title: t(`${en_vi}.appendix3Number`),
			dataIndex: "appendix3Number"
		},
		{
			title: t(`${en_vi}.medicalLevel`),
			dataIndex: "medicalLevel"
		},
		{
			title: t(`${en_vi}.departmentCode`),
			dataIndex: "departmentCode"
		},
		{
			title: t(`${en_vi}.remarks`),
			dataIndex: "remarks"
		},
		{
			title: t(`${en_vi}.bidQuantity`),
			dataIndex: "bidQuantity"
		},
		{
			title: t(`${en_vi}.procurementMethod`),
			dataIndex: "procurementMethod"
		},
		{
			title: t(`${en_vi}.bidStorageQuantity`),
			dataIndex: "bidStorageQuantity"
		},
		{
			title: t(`${en_vi}.outsideHours`),
			dataIndex: "outsideHours"
		},
		{
			title: t(`${en_vi}.bidYear`),
			dataIndex: "bidYear"
		},
		{
			title: t(`${en_vi}.contractNumber`),
			dataIndex: "contractNumber"
		},
		{
			title: t(`${en_vi}.contractDate`),
			dataIndex: "contractDate"
		},
		{
			title: t(`${en_vi}.compensationDecision`),
			dataIndex: "compensationDecision"
		},
		{
			title: t(`${en_vi}.objectGroup`),
			dataIndex: "objectGroup"
		},
		{
			title: t(`${en_vi}.icdCode`),
			dataIndex: "icdCode"
		},
		{
			title: t(`${en_vi}.minimumPrice`),
			dataIndex: "minimumPrice"
		},
		{
			title: t(`${en_vi}.hospitalId`),
			dataIndex: "hospitalId"
		},
		{
			title: t(`${en_vi}.regulation22Code`),
			dataIndex: "regulation22Code"
		},
		{
			title: t(`${en_vi}.warningGroup`),
			dataIndex: "warningGroup"
		},
		{
			title: t(`${en_vi}.regulation2182Code`),
			dataIndex: "regulation2182Code"
		},
		{
			title: t(`${en_vi}.regulation2182Usage`),
			dataIndex: "regulation2182Usage"
		},
		{
			title: t(`${en_vi}.hasRecord`),
			dataIndex: "hasRecord"
		},
		{
			title: t(`${en_vi}.componentCode5084`),
			dataIndex: "componentCode5084"
		},
		{
			title: t(`${en_vi}.doctorCode`),
			dataIndex: "doctorCode"
		},
		{
			title: t(`${en_vi}.bidUsagePeriod`),
			dataIndex: "bidUsagePeriod"
		},
		{
			title: t(`${en_vi}.secondBidQuantity`),
			dataIndex: "secondBidQuantity"
		},
		{
			title: t(`${en_vi}.warehouseGroup`),
			dataIndex: "warehouseGroup"
		},
		{
			title: t(`${en_vi}.averageQuantity`),
			dataIndex: "averageQuantity"
		},
		{
			title: t(`${en_vi}.hospitalGroup`),
			dataIndex: "hospitalGroup"
		},
		{
			title: t(`${en_vi}.largeExpenseFlag`),
			dataIndex: "largeExpenseFlag"
		},
		{
			title: t(`${en_vi}.usageMinutes`),
			dataIndex: "usageMinutes"
		},
		{
			title: t(`${en_vi}.storageReserveLock`),
			dataIndex: "storageReserveLock"
		},
		{
			title: t(`${en_vi}.insurancePrice2`),
			dataIndex: "insurancePrice2"
		},
		{
			title: t(`${en_vi}.paymentTargetCode`),
			dataIndex: "paymentTargetCode"
		},
		{
			title: t(`${en_vi}.typeCode2`),
			dataIndex: "typeCode2"
		},
		{
			title: t(`${en_vi}.warningFlag`),
			dataIndex: "warningFlag"
		},
		{
			title: t(`${en_vi}.insuranceDrug`),
			dataIndex: "insuranceDrug"
		},
		{
			title: t(`${en_vi}.serviceDrug`),
			dataIndex: "serviceDrug"
		},
		{
			title: t(`${en_vi}.defectiveQuantity`),
			dataIndex: "defectiveQuantity"
		},
		{
			title: t(`${en_vi}.insuranceType2`),
			dataIndex: "insuranceType2"
		},
		{
			title: t(`${en_vi}.taxExcludedPrice`),
			dataIndex: "taxExcludedPrice"
		},
		{
			title: t(`${en_vi}.bidStatus`),
			dataIndex: "bidStatus"
		},
		{
			title: t(`${en_vi}.startDate`),
			dataIndex: "startDate"
		},
		{
			title: t(`${en_vi}.endDate`),
			dataIndex: "endDate"
		},
		{
			title: t(`${en_vi}.sendDate`),
			dataIndex: "sendDate"
		},
		{
			title: t(`${en_vi}.approvalDate`),
			dataIndex: "approvalDate"
		},
		{
			title: t(`${en_vi}.lockReserveTarget`),
			dataIndex: "lockReserveTarget"
		},
		{
			title: t(`${en_vi}.lockReserveCategory`),
			dataIndex: "lockReserveCategory"
		},
		{
			title: t(`${en_vi}.usageYear`),
			dataIndex: "usageYear"
		},
		{
			title: t(`${en_vi}.productionYear`),
			dataIndex: "productionYear"
		},
		{
			title: t(`${en_vi}.source`),
			dataIndex: "source"
		},
		{
			title: t(`${en_vi}.inspectionExpiry`),
			dataIndex: "inspectionExpiry"
		},
		{
			title: t(`${en_vi}.inspectionDate`),
			dataIndex: "inspectionDate"
		},
		{
			title: t(`${en_vi}.department`),
			dataIndex: "department"
		},
		{
			title: t(`${en_vi}.inspectionUnit`),
			dataIndex: "inspectionUnit"
		},
		{
			title: t(`${en_vi}.salesRatioGroup`),
			dataIndex: "salesRatioGroup"
		},
		{
			title: t(`${en_vi}.insuranceSales`),
			dataIndex: "insuranceSales"
		},
		{
			title: t(`${en_vi}.serviceSales`),
			dataIndex: "serviceSales"
		},
		{
			title: t(`${en_vi}.targetCode1`),
			dataIndex: "targetCode1"
		},
		{
			title: t(`${en_vi}.axName`),
			dataIndex: "axName"
		},
		{
			title: t(`${en_vi}.insurance30Days`),
			dataIndex: "insurance30Days"
		},
		{
			title: t(`${en_vi}.ingredientCode30`),
			dataIndex: "ingredientCode30"
		},
		{
			title: t(`${en_vi}.pharmacyCode`),
			dataIndex: "pharmacyCode"
		},
		{
			title: t("felix_ui.action"),
			dataIndex: "action",
			fixed: "right",
			render: (_: any, record: any) => (
				<TableAction
					actions={[
						{
							icon: IconEnum.EDIT,
							label: t("felix_ui.edit"),
							onClick: handleEdit.bind(null, record)
						},
						{
							icon: IconEnum.DELETE,
							danger: true,
							label: t("felix_ui.delete"),
							popConfirm: {
								title: t("felix_ui.delMessage"),
								placement: "top",
								confirm: handleDelete.bind(null, record.id)
							}
						}
					]}
				></TableAction>
			)
		}
	];

	const [registerTable, { reload }] = useTable({
		api: DrugInfoApi.getDrugInfoPage,
		columns,
		formConfig: {
			labelWidth: 120,
			schemas,
			showActionButtonGroup: true,
			baseColProps: { span: 6 },
			actionColOptions: { span: 12 }
		},
		showTableSetting: true,
		bordered: true,
		useSearchForm: true
	});
	const [registerDrawer, { openDrawer }] = useDrawer();
	const handleEdit = (record: any) => {
		openDrawer(true, {
			reload,
			record,
			isUpdated: true
		});
	};
	//表格导出
	const exportExcel = async () => {
		await DrugInfoApi.getDrugInfoPage({}).then(res => {
			exportToExcel(res.list, t("felix_ui.pat_basic_info"));
		});
	};
	//删除角色
	const handleDelete = async (id: number) => {
		// 发起删除
		const res = await DrugInfoApi.deleteDrugInfo(id);
		reload();
		if (!res) return message.error(t("viewComponents.patientInformation.deleteFailed"));
		message.success(t("viewComponents.patientInformation.deleteSuccessfully"));
	};
	const handlerToolbarAction = async (key: string) => {
		switch (key) {
			case "add":
				openDrawer(true, {
					reload,
					isUpdated: false
				});
				break;
			case "export":
				exportExcel();
				break;
		}
	};
	return (
		<div className="page">
			<div className="page-content">
				<BasicTable register={registerTable}></BasicTable>
				<CreateAndUpdata register={registerDrawer}></CreateAndUpdata>
			</div>
			<Toolbar action={handlerToolbarAction} btnList={["add", "export"]} />
		</div>
	);
};
export default index;
